<?php

namespace maotool\src\test;

use maotool\cache\CacheUtil;
use maotool\file\DirUtil;
use maotool\file\FileUtil;
use maotool\log\Console;
use maotool\object\ReflectionUtil;
use maotool\thread\ThreadUtil;
use maotool\util\IdUtil;
use maotool\util\PathUtil;
use maotool\util\ProjectUtil;
use PHPUnit\Framework\TestCase;

class CacheUtilTest extends TestCase
{

    public function testDemo1()
    {
        $log_time_start = microtime(true);
        $a = CacheUtil::tags(['1', '2'])->get("aaaa", function () {
            sleep(1);
            return [1,2,3,4,5];
        });
        CacheUtil::tags(['1', '2', '3'])->get("bbb", function () {
            sleep(1);
            return [1,2,3,4,5];
        });
        CacheUtil::tags(['1'])->get("ccc", function () {
            sleep(1);
            return [1,2,3,4,5];
        });
//        CacheUtil::tags(['2'])->clear();
        Console::debug('请求加载用时：' . number_format(microtime(true) - $log_time_start, 10) . ' 秒。');
        $lines = Console::$lines;
        foreach ($lines as $line) {
            echo json_encode($line["ages"], JSON_UNESCAPED_UNICODE) . "\n";
        }
        $d_cache = DirUtil::$cache;
        $f_cache = FileUtil::$cache;
        $r_cache = ReflectionUtil::$cache;
        $this->assertTrue(true);
    }

    public function testDemo2()
    {
        CacheUtil::remove("aaaa");
        $this->assertTrue(true);
    }

    public function testDemo3()
    {
        $data = CacheUtil::get("test", "default");
        var_dump($data);
        $this->assertTrue(true);
    }

    public function testDemo4()
    {
        var_dump(CacheUtil::clear());
        $this->assertTrue(true);
    }

    public function testDemo5()
    {
        var_dump(CacheUtil::expire());
        $this->assertTrue(true);
    }

}